<script type="text/javascript" language="javascript1.4">
<!--
{literal}
function formElementAdd(id, key){
	var aList = new Array();
	var bodys = document.forms['form'+id];
	var count = 0;
	var slastKey = 0;
	var aTmp = new Array();	
	var re = /\[(\w+)\_/;
	
	for (var index = 0; index < bodys.length; index++) {
		myArray = bodys.elements[index].name.match(re);
		if (myArray != null) x_key = myArray[1];
		else x_key = null;
		if ((bodys.elements[index].name.indexOf('form_array') != -1) && (parseInt(x_key, 10)>parseInt(key, 10)) && (bodys.elements[index].name != 'undefined')){
			aList[count] = bodys.elements[index].name;
			count ++;
			if (parseInt(x_key, 10) > parseInt(slastKey, 10)){
				slastKey = parseInt(x_key, 10);
			}
		}
	}

	for (var index = aList.length-1; index > 0; index--) {
		myArray = aList[index].match(re);
		if (myArray != null) cur_key = myArray[1];
		else cur_key = null;
		if ((aTmp[cur_key] == undefined) && (cur_key != null)) {
			aTmp[cur_key] = aList[index];
			var empty_div = document.getElementById('div_'+cur_key).outerHTML;

			var iNewKey = parseInt(cur_key, 10)+1;
			if (iNewKey < 10) iNewKey = "0"+iNewKey;
			curent_div = eval("empty_div.replace(/div_"+cur_key+">/gi, 'div_"+iNewKey+">')");
			curent_div = eval("curent_div.replace(/width=15>"+cur_key+"/gi, 'width=15>"+iNewKey+"')");
			curent_div = eval("curent_div.replace(/"+cur_key+"_/gi, '"+iNewKey+"_')");
			curent_div = eval("curent_div.replace(/'"+cur_key+"'/gi, '\\'"+iNewKey+"\\'')");
            document.getElementById('div_'+cur_key).outerHTML = curent_div;
		}
	}

	var iNewKey = parseInt(key, 10)+1;
	if (iNewKey < 10) iNewKey = "0"+iNewKey;
	slastKey = parseInt(slastKey, 10) + 1;
	if (slastKey < 10) slastKey = "0"+slastKey;

	empty_div = document.getElementById('div_'+slastKey).outerHTML;
	empty_div = eval("empty_div.replace(/div_"+slastKey+">/g, 'div_"+iNewKey+">')");
	empty_div = eval("empty_div.replace(/width=15>"+slastKey+"/g, 'width=15>"+iNewKey+"')");
	empty_div = eval("empty_div.replace(/"+slastKey+"_/g, '"+iNewKey+"_')");
	empty_div = eval("empty_div.replace(/'"+slastKey+"'/g, '\\'"+iNewKey+"\\'')");
	curent_div = document.getElementById('div_'+key).outerHTML;
	curent_div = curent_div + empty_div;
	document.getElementById('div_'+key).outerHTML = curent_div;
	
}

function formElementChangeType(el_nr, type, action){
	switch(type){
		case "empty":
			if (action == 1) alert('{/literal}{t t='Šis laukas bus ištrintas!'}{literal}');
		case "br":
			document.getElementById(el_nr + "_name01").disabled = true;
			document.getElementById(el_nr + "_param01").disabled = true;
			document.getElementById(el_nr + "_req01").disabled = true;
			document.getElementById(el_nr + "_mail01").disabled = true;
			break;
		case "divider":
			document.getElementById(el_nr + "_name01").disabled = true;
			document.getElementById(el_nr + "_param01").disabled = true;
			document.getElementById(el_nr + "_req01").disabled = true;
			document.getElementById(el_nr + "_mail01").disabled = true;
			break;
		case "label":
			document.getElementById(el_nr + "_name01").disabled = false;
			document.getElementById(el_nr + "_param01").disabled = true;
			document.getElementById(el_nr + "_req01").disabled = true;
			document.getElementById(el_nr + "_mail01").disabled = true;
			break;
		case "email":
			document.getElementById(el_nr + "_name01").disabled = false;
			document.getElementById(el_nr + "_param01").disabled = true;
			document.getElementById(el_nr + "_req01").disabled = false;
			document.getElementById(el_nr + "_mail01").disabled = false;
			break;
		case "text":
		case "textarea":
		case "url":
		case "file":
			document.getElementById(el_nr + "_name01").disabled = false;
			document.getElementById(el_nr + "_param01").disabled = true;
			document.getElementById(el_nr + "_req01").disabled = false;
			document.getElementById(el_nr + "_mail01").disabled = true;
			break;
		case "checkbox":
		case "radio":
		case "select":
			document.getElementById(el_nr + "_name01").disabled = false;
			document.getElementById(el_nr + "_param01").disabled = false;
			document.getElementById(el_nr + "_req01").disabled = false;
			document.getElementById(el_nr + "_mail01").disabled = true;
			break;
	}
}
{/literal}
//-->
</script>
<div id="form_div">
{assign var='ct' value='1'}
{ext->get_field_id assign="parent" name=$el.name parent=$data.page.id}
<input type="hidden" name="form_id" value="{$parent}">
{ext->get_form_elements assign="forms" parent=$parent}
{assign var="f_counter" value=0}
{foreach from=$forms item="form" key="key"}
{if ($smarty.get.group_id && $key != "00" && $key != "01") || (!$smarty.get.group_id)}
{math equation="x+y" x=$ct y=1 assign="ct"}
<div id="div_{$key}">
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td height="1" bgcolor="#DBE1E5"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
	</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" bgcolor="#F8F9F9">	
	<tr>
		<td width="15" height="30"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td width="15">{$key}.</td>
		<td width="5"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td align="left" width="200">
			{capture name="keys"}{$key}_type01{/capture}{assign var="k" value=$smarty.capture.keys}
			<select onChange="formElementChangeType('{$key}', this.value, 1);" id="{$key}_type01" name="form_array[{$key}_type01]" style="width:200px ">
					<option value=empty {if (($form.$k.value == '') or ($form.$k.value == 'empty'))}selected{/if}>{t t='i š t r i n t i'}</option>
					<option value=br {if $form.$k.value == 'br'}selected{/if}>{t t='- Tarpas -'}</option>
					<option value=divider {if $form.$k.value == 'divider'}selected{/if}>{t t='- Skiriamoji linija -'}</option>
					<option value=text {if $form.$k.value == 'text'}selected{/if}>{t t='Tekstinis laukelis'}</option>
					<option value=label {if $form.$k.value == 'label'}selected{/if}>{t t='Tekstinis intarpas'}</option>
					<option value=textarea {if $form.$k.value == 'textarea'}selected{/if}>{t t='Tekstas'}</option>
					<option value=select {if $form.$k.value == 'select'}selected{/if}>{t t='Išsiskleidžiantis sąrašas'}</option>
					<option value=radio {if $form.$k.value == 'radio'}selected{/if}>{t t='Išsirinkimo sąrašas'}</option>
					<option value=checkbox {if $form.$k.value == 'checkbox'}selected{/if}>{t t='Pasirinkimo sąrašas'}</option>
					<option value=url {if $form.$k.value == 'url'}selected{/if}>{t t='Interneto adresas'}</option>
					<option value=email {if $form.$k.value == 'email'}selected{/if}>{t t='El. pašto adresas'}</option>
					<option value=file {if $form.$k.value == 'file'}selected{/if}>{t t='Failas'}</option>
			</select>
		</td>
		<td style="padding-left:15px; text-align:left" align="left" width="30%">
			{capture name="keys"}{$key}_name01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="text" id="{$key}_name01" name="form_array[{$key}_name01]" value="{$form.$k.value}" class="defaultInputText" style="width:100%;">
		</td>		
		<td style="padding-left:15px; padding-right:10px;">
			{capture name="keys"}{$key}_param01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="text" id="{$key}_param01" name="form_array[{$key}_param01]" value="" class="defaultInputText" style="width:100%;">
			<script language="javascript" type="text/javascript">addValueAndFieldToSpacify ('{$key}_param01','{$form.$k.value|escape:"quotes"}');</script>
		</td>		
		<td width="30">
			{capture name="keys"}{$key}_req01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="checkbox" id="{$key}_req01" name="form_array[{$key}_req01]" {if $form.$k.value == 'on'}checked{/if}>
		</td>		
		<td width="30">
			{capture name="keys"}{$key}_mail01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="checkbox" id="{$key}_mail01" name="form_array[{$key}_mail01]" {if $form.$k.value == 'on'}checked{/if}>
		</td>		
		<td width="15" onclick="formElementAdd('{$data.page.id}', '{$key}'); return false;" style="cursor:pointer;">
			<a href="#"><img src="{$_http_path}/_tvs_system_core_/design/img/red_plius.gif"/></a>
		</td>	
	</tr>
	<tr>
		<td width="15" height="30"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td width="15"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td width="5"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td colspan="4">
			{capture name="keys"}{$key}_text01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="text" id="{$key}_text01" name="form_array[{$key}_text01]" value="{$form.$k.value}" class="defaultInputText" style="width:100%;">
		</td>
	</tr>
</table>
</div>
{capture name="keys"}{$key}_type01{/capture}{assign var="k" value=$smarty.capture.keys}
<script>formElementChangeType('{$key}', '{$form.$k.value}', 0);</script>
{/if}
{/foreach}

{if !$key}{math equation="x-y" x=$f_counter y=1 assign="key"}{/if}
{capture name="keys"}{$key}_type01{/capture}{assign var="k" value=$smarty.capture.keys}{assign var="last_type" value=$form.$k.value}
{capture name="keys"}{$key}_name01{/capture}{assign var="k" value=$smarty.capture.keys}{assign var="last_name" value=$form.$k.value}
{capture name="keys"}{$key}_param01{/capture}{assign var="k" value=$smarty.capture.keys}{assign var="last_param" value=$form.$k.value}
{capture name="keys"}{$key}_req01{/capture}{assign var="k" value=$smarty.capture.keys}{assign var="last_req" value=$form.$k.value}
{capture name="keys"}{$key}_mail01{/capture}{assign var="k" value=$smarty.capture.keys}{assign var="last_mail" value=$form.$k.value}

{if (($last_type != 'empty') or ($last_name != '') or ($last_param != ''))}
	{math equation="x + 1" x=$key|string_format:"%d" assign="key"}
	{if $key < 10}{capture name="keys"}0{$key}{/capture}{assign var="key" value=$smarty.capture.keys}{/if}
<div id="div_{$key}">
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td height="1" bgcolor="#DBE1E5"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
	</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" bgcolor="#F8F9F9">	
	<tr>
		<td width="15" height="30"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td width="15">{$key}.</td>
		<td width="5"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td align="left" width="200">
			{capture name="keys"}{$key}_type01{/capture}{assign var="k" value=$smarty.capture.keys}
			<select onChange="formElementChangeType('{$key}', this.value, 1);" id="{$key}_type01" name="form_array[{$key}_type01]" style="width:200px ">
					<option value=empty {if (($form.$k.value == '') or ($form.$k.value == 'empty'))}selected{/if}>{t t='i š t r i n t i'}</option>
					<option value=br {if $form.$k.value == 'br'}selected{/if}>{t t='- Tarpas -'}</option>
					<option value=divider {if $form.$k.value == 'divider'}selected{/if}>{t t='- Skiriamoji linija -'}</option>
					<option value=label {if $form.$k.value == 'label'}selected{/if}>{t t='Tekstinis intarpas'}</option>
					<option value=text {if $form.$k.value == 'text'}selected{/if}>{t t='Tekstinis laukelis'}</option>
					<option value=textarea {if $form.$k.value == 'textarea'}selected{/if}>{t t='Tekstas'}</option>
					<option value=select {if $form.$k.value == 'select'}selected{/if}>{t t='Išsiskleidžiantis sąrašas'}</option>
					<option value=radio {if $form.$k.value == 'radio'}selected{/if}>{t t='Išsirinkimo sąrašas'}</option>
					<option value=checkbox {if $form.$k.value == 'checkbox'}selected{/if}>{t t='Pasirinkimo sąrašas'}</option>
					<option value=url {if $form.$k.value == 'url'}selected{/if}>{t t='Interneto adresas'}</option>
					<option value=email {if $form.$k.value == 'email'}selected{/if}>{t t='El. pašto adresas'}</option>
					<option value=file {if $form.$k.value == 'file'}selected{/if}>{t t='Failas'}</option>
			</select>
		</td>
		<td style="padding-left:15px; text-align:left" align="left" width="30%">
			{capture name="keys"}{$key}_name01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="text" id="{$key}_name01" name="form_array[{$key}_name01]" value="{$form.$k.value}" class="defaultInputText" style="width:100%;">
		</td>		
		<td style="padding-left:15px; padding-right:10px;">
			{capture name="keys"}{$key}_param01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="text" id="{$key}_param01" name="form_array[{$key}_param01]" value="{$form.$k.value}" class="defaultInputText" style="width:100%;">
		</td>		
		<td width="30">
			{capture name="keys"}{$key}_req01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="checkbox" id="{$key}_req01" name="form_array[{$key}_req01]" {if $form.$k.value == 'on'}checked{/if}>
		</td>
		<td width="30">
			{capture name="keys"}{$key}_mail01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="checkbox" id="{$key}_mail01" name="form_array[{$key}_mail01]" {if $form.$k.value == 'on'}checked{/if}>
		</td>	
		<td width="15">
			<img src="client/img/spacer.gif" class="spacer" alt="" />
		</td>		
	</tr>
	<tr>
		<td width="15" height="30"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td width="15"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td width="5"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
		<td colspan="4">
			{capture name="keys"}{$key}_text01{/capture}{assign var="k" value=$smarty.capture.keys}
			<input type="text" id="{$key}_text01" name="form_array[{$key}_text01]" value="{$form.$k.value}" class="defaultInputText" style="width:100%;">
		</td>
	</tr>
</table>
	<script>formElementChangeType('{$key}', 'empty', 0);</script>
{/if}
</div>
</div>